const express = require('express');
const router = express.Router();
const pool = require('../dao/pool');

// 获取所有题目类型，返回id，类型名称
router.get('/getType',(req,res)=>{
    let sql = 'select id,type from type';
    pool.query(sql,(err,result)=>{
        if (err) throw err
        res.send(result)
    })
})

// 根据类型id获取题目，返回该类型id下的随机10道题目
router.get('/getSubject',(req,res)=>{
    let params = [req.query.id]
    let sql = 'select id,title,option1,option2,option3,option4,answer from subject where type_id=? order by rand() limit 10';
    pool.query(sql,params,(err,results)=>{
        if (err) throw err
        res.send(results);
    })
})

module.exports = router;